package com.fanqiechaodan.memento;

import com.alibaba.fastjson.JSON;

/**
 * @author fanqiechaodan
 * @Classname Demo
 * @Description 备忘录模式
 */
public class Demo {

    public static void main(String[] args) {
        Role role = new Role(100,50,20);
        Caretaker caretaker = new Caretaker();
        Memento memento = role.save();
        caretaker.addMemento(memento);
        // 攻击力+10
        role.setAttack(role.getAttack()+10);
        System.out.println(JSON.toJSONString(role));
        // 恢复
        role.restore(caretaker.getMemento(0));
        System.out.println(JSON.toJSONString(role));
    }
}
